# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=http-download
pkgname=haskell-http-download
pkgver=0.2.1.0
pkgrel=39
pkgdesc="Verified downloads with retries"
url="https://github.com/commercialhaskell/http-download"
license=('MIT')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-base64-bytestring' 'haskell-conduit' 'haskell-conduit-extra'
         'haskell-crypton' 'haskell-crypton-conduit' 'haskell-http-client' 'haskell-http-conduit'
         'haskell-http-types' 'haskell-memory' 'haskell-path' 'haskell-path-io' 'haskell-retry'
         'haskell-rio' 'haskell-rio-prettyprint')
makedepends=('ghc' 'uusi' 'haskell-hspec' 'haskell-hspec-discover')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('75a208684bf4f116746a1015870a6bb2afbdd1a4b4c268b88f142b189e0e31c59b8d691606c3eb33be9b1637a0131c4d7cb48091179f22bba8d6d2919ce30e02')

prepare() {
    cd $_hkgname-$pkgver
    gen-setup
}

build() {
    cd $_hkgname-$pkgver    
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
